package com.twu.biblioteca;

import com.twu.stub.StubBufferRead;

import java.io.*;
import java.util.Scanner;

public class BibliotecaApp {

    public static void MainLoop(BufferedReader in, PrintStream out)
    {
        try {
            BibliotecaShow.newcustomer(out);
<<<<<<< HEAD
            Command command = null;
            do {
                //Scanner input = new Scanner(in);
                BibliotecaShow.showOptionMenu(out);
=======
            BibliotecaShow.showOptionMenu(out);
            Command command = null;
            do {
                //Scanner input = new Scanner(in);
>>>>>>> 35da6d08a71d87cd8b6d18bacb866f3b865fbf23
                String content = in.readLine();
                String[] contentlist = content.split(" ");
                if( contentlist.length > 0 )
                {
                    command = CommandParser.getCommand(contentlist[0]);
                    if(command == null)
                        BibliotecaShow.showInvalidOption(out);
                    else
                        if(contentlist.length>1)
<<<<<<< HEAD
                        {
                            String temp = "";
                            for(int i =1;i<contentlist.length; ++i)
                            {
                                temp += contentlist[i] + " ";
                            }
                            temp = temp.substring(0, temp.length()-1);
                            command.execute(temp, out);
                        }
=======
                            command.execute(contentlist[1], out);
>>>>>>> 35da6d08a71d87cd8b6d18bacb866f3b865fbf23
                        else
                            command.execute(contentlist[0], out);
                }
            }
            while( command != null && CommandType.CMD_QUIT != command.type() );
<<<<<<< HEAD
=======
            BibliotecaShow.goodbye(out);
>>>>>>> 35da6d08a71d87cd8b6d18bacb866f3b865fbf23
        }
        catch (Exception e)
        {

        }

    }

    public static void main(String[] args) {
        final InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        MainLoop(new BufferedReader(inputStreamReader), System.out);
    }
}
